/**
* \file	Value.cpp
* \author Caio Arce Nishibe (caionishibe@gmail.com)
* \date	August, 2014
* \brief Value Implementation.
*/
#include "Value.h"

Value::Value()
{
	this->number = 0;

}

Value::~Value()
{

}

void Value::GetValue(Type type, void *val)
{
	if (type == DOUBLE)
		*((double *)val) = this->number;
	else if (type == STRING)
		*((std::string *)val) = this->str;
	else if (type == COMPARATOR)
		*((CompOp *)val) = this->compOp;
	else if (type == LOGIC)
		*((LogicOp *)val) = this->logicOp;
	else if (type == ARITHMETIC)
		*((ArithOp *)val) = this->arithOp;
	else
	{
		fprintf(stderr, "Common.c: GetValue: unknown type\n");
		exit(1);
	}
}

void Value::SetValue(Type type, void *val)
{
	if (type == VOID)
	{
		this->number = 0;
	}
	else if (type == DOUBLE)
	{
		this->number = *((double *)val);
	}
	else if (type == STRING)
	{
		this->str = *((std::string *)val);
	}
	else if (type == COMPARATOR)
	{
		this->compOp = *((CompOp*)val);
	}
	else if (type == LOGIC)
	{
		this->logicOp = *((LogicOp*)val);
	}
	else if (type == ARITHMETIC)
	{
		this->arithOp = *((ArithOp*)val);
	}
	else
	{
		fprintf(stderr, "Common.c: SetValue: unknown type\n");
		exit(1);
	}
}


void Value::SetValueFromString(std::string str)
{
	SetValue(STRING, (void *)(&str));
}

void Value::SetValueFromNumber(double number)
{
	SetValue(DOUBLE, (void *)(&number));
}

void Value::SetValueFromOpComp(CompOp op)
{
	SetValue(COMPARATOR, (void *)(&op));
}

void Value::SetValueFromOpLogic(LogicOp op)
{
	SetValue(LOGIC, (void *)(&op));
}

void Value::SetValueFromOpArit(ArithOp op)
{
	SetValue(ARITHMETIC, (void *)(&op));
}

void Value::PrintValue(Type type)
{
	if (type == DOUBLE)
	{
		cout << this->number;
	}
	else if (type == STRING)
	{
		cout << this->str;
	}
}

